#include <iostream>
#include<queue>

using namespace std;

const int N = 1e6 + 10;
int l[N], r[N];
int n;

void bfs()
{
	queue<int> q;
	q.push(1);
	
	while(q.size())
	{
		int u = q.front();
		cout << u << " ";
	    q.pop();
		if(l[u]) 
	        q.push(l[u]);
	    if(r[u])
	        q.push(r[u]);
	}
	cout << endl;
}
int main()
{
	cin >> n;
	for(int i =1; i <= n; i++)
	{
		cin >> l[i] >> r[i];
	}
	bfs();
	return 0;
}
